
import NumberState from "./index";


let reducer = (state = {...NumberState.state}, action:{type:string, val:number}) => {
    let newState = JSON.parse(JSON.stringify(state));
    // switch (action.type) {
    //     case NumberState.add1:
    //         NumberState.actions[NumberState.add1](newState,action)
    //         break;
    //     case NumberState.add2:
    //         NumberState.actions[NumberState.add2](newState,action)
    //         break;
        
    //     default:
    //         break;
    // }

    for (const key in NumberState.actionNames) {
        if (action.type === NumberState.actionNames[key]) {
            NumberState.actions[NumberState.actionNames[key]](newState, action);
            break;
        }
    }
    
    return newState;
}

export default reducer;